import Vue from 'vue'
import Router from 'vue-router'
/* import home from '../components/home.vue'
import about from '../components/about.vue' */
const home = () => import('../components/home.vue')
const homechild = () => import('../components/homechild.vue')
const aboutchild = () => import('../components/aboutchild.vue')
const about = () => import('../components/about.vue')
const user = () => import('../components/user.vue')
const profile = () => import('../components/profile.vue')


Vue.use(Router)

const router = new Router({
  routes: [{
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'home',
      component: home,
      meta: {
        title: '首页'
      },
      children: [{
          path: '',
          redirect: 'homechild'
        },
        {
          path: 'homechild',
          component: homechild
        },
        {
          path: 'aboutchild',
          component: aboutchild
        }
      ]
    },
    {
      path: '/about',
      name: 'about',
      component: about,
      meta: {
        title: '关于'
      }
    },
    {
      path: '/user:user_id',
      component: user,
      meta: {
        title: '用户'
      }
    },
    {
      path: '/profile',
      component: profile,
      meta: {
        title: '我的'
      }
    }
  ],
  mode: 'history'
})
router.beforeEach((to, from, next) => {
  //from跳转到to
  document.title = to.matched[0].meta.title
  console.log(to);

  next()
})
export default router
